package com.k.configcenter.nacos.listener;

import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.Executor;

/**
 * Nacos 配置监听
 * @author ljw
 */
@Component
public class ConfigStatusListener {
    @Autowired
    private NacosConfigManager nacosConfigManager;
    @PostConstruct
    public void init() throws NacosException {

        System.out.println("nacosConfigManager-nacosConfigProperties:"+nacosConfigManager.getNacosConfigProperties());

        String dataId = "common.properties";
        String group = "ucmsgroup";
        nacosConfigManager.getConfigService().addListener(dataId,group, new Listener() {
            @Override
            public void receiveConfigInfo(String configInfo) {
                System.out.println("received001:\r\n" + configInfo);
            }
            @Override
            public Executor getExecutor() {
                return null;
            }
        });

    }
}